package smoker.tools;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;

public class GUIManager {
	
	public static JLabel createJLabel(String title) {
		JLabel lab = new JLabel(title);
		return lab;
	}
	
	public static JButton createJButton(String title, ImageIcon icon, 
			ActionListener action, String actionCommand) {
		JButton btn = new JButton(title);
		btn.setIcon(icon);
		btn.addActionListener(action);
		btn.setActionCommand(actionCommand);
		return btn;
	}
	
	public static JTextField createJTextField(String title) {
		JTextField tf = new JTextField(title);
		return tf;
	}
	
	public static JMenuItem createMenuItem(String title, ActionListener action, String command) {
		JMenuItem menuItem = new JMenuItem(title);
		menuItem.addActionListener(action);
		menuItem.setActionCommand(command);
		return menuItem;
	}
	
	public static ImageIcon[] getDptIcon() {
		ImageIcon[] icons = new ImageIcon[4];
		for (int i = 0; i < icons.length; i++) {
			icons[i] = new ImageIcon("image/DepartmentPhoto/" + (i+1) + ".png");
		}
		return icons;
	}
	
	public static ImageIcon[][] headerIcon() {
		int index = 0;
		ImageIcon[][] icons = new ImageIcon[13][10];
		for (int i = 0; i < 13; i++) {
			for (int j = 0; j < 10; j++) {
				icons[i][j] = new ImageIcon("image/UserPhoto/" + (++index) + ".PNG");
			}
		}
		return icons;
	}
	
	public static DefaultMutableTreeNode createDefaultMutableTreeNode(String title) {
		DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(title);
		return treeNode;
	}
	
	public static void setConstraints(GridBagLayout gbl, GridBagConstraints gbc,
			int gridx, int gridy, int gridWidth, int gridHeight,
			double weightx, double weighty ) {
		gbc.gridx = gridx;
		gbc.gridy = gridy;
		gbc.gridheight = gridHeight;
		gbc.gridwidth = gridWidth;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
	}
	
	public static void CenterWindow(Component frame) {
		Toolkit kit = Toolkit.getDefaultToolkit();
		int width = kit.getScreenSize().width;
		int height= kit.getScreenSize().height;
		int windowWidth = frame.getSize().width;
		int windowHeight= frame.getSize().height;
		
		windowWidth = (windowWidth > width) ? width : windowWidth;
		windowHeight= (windowHeight> height) ? height : windowHeight;
		frame.setSize(windowWidth, windowHeight);
		
		int xPos = (width - windowWidth) / 2;
		int yPos = (height - windowHeight) / 2;
		frame.setLocation(xPos, yPos);
	}
	
	public static void rightBottomWindow(Component frame) {
		Toolkit kit = Toolkit.getDefaultToolkit();
		int width = kit.getScreenSize().width;
		int height= kit.getScreenSize().height;
		int windowWidth = frame.getSize().width;
		int windowHeight= frame.getSize().height;
		
		windowWidth = (windowWidth > width) ? width : windowWidth;
		windowHeight= (windowHeight> height) ? height : windowHeight;
		frame.setSize(windowWidth, windowHeight);
		
		int xPos = width;
		int yPos = height;
		frame.setLocation(xPos - 200, yPos - 150);
	}
	
	public static void moveToTopRightCorner(Component frame) {
		Toolkit kit = Toolkit.getDefaultToolkit();
		int width = kit.getScreenSize().width;
		int height= kit.getScreenSize().height;
		int windowWidth = frame.getSize().width;
		int windowHeight= frame.getSize().height;
		windowWidth = (windowWidth > width) ? width : windowWidth;
		windowHeight= (windowHeight> height) ? height : windowHeight;
		frame.setSize(windowWidth, windowHeight);
		int xPos = (width - windowWidth);
		frame.setLocation(xPos - 10, 10);
	}
	
	public static Dimension MaxWindow() {
		Dimension dim = new Dimension();
		Toolkit kit = Toolkit.getDefaultToolkit();
		dim.width = kit.getScreenSize().width;
		dim.height= kit.getScreenSize().height;
		return dim;
	}
}
